<template>
  <div class="AddOrUpdate_main add_container tenantMenu_main main_container user_container">
    <div class="main_main">
      <div class="main_main_container">
        <div class="main_main_left">
          <div class="title">部门</div>
          <div class="main_main_left_top">
            <el-tree
              :data="teamListArr"
              :expand-on-click-node="false"
              :default-expand-all="true"
              :highlight-current="true"
              :props="defaultProps"
              @node-click="singleElection"
            />
          </div>
        </div>
        <div class="main_main_right">
          <div class="SearchBar_main main_main_search">
            <div class="main_main_search_item">
              <div class="formItem_header">
                <div class="formItem_header_operate">
                  <a class="formItem_header_operate_items" @click="add">
                    <svg-icon icon-class="新增" />
                    <div class="item_name">新增</div>
                  </a>
                </div>
              </div>
            </div>
            <div class="main_main_search_item">
              <el-input v-model="pageData.searchValue" placeholder="请输入姓名或手机号" clearable @keyup.enter.native="loadPeople" @clear="loadPeople" />
              <el-button icon="el-icon-search" @click.stop="loadPeople" />
            </div>
          </div>
          <div ref="table_container" class="table_container">
            <!-- <div class="twoTable"> -->
            <!-- <el-table
            ref="table"
            :data="tableData"
            stripe border
            :height="tableHeight"
            style="width: 30%;margin-right:100px;"
            row-key="menuId"
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
            @sort-change="(column)=>{sortChange(column, this)}"
            @row-click="singleElection"
          >
            <el-table-column label="" width="65">
              <template slot-scope="scope">
                <el-radio
                  v-model="templateSelection"
                  class="radio"
                  :label="scope.row.id"
                >{{ '' }}</el-radio>
              </template>
            </el-table-column>
            <Column v-for="(column,index) in teamColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          </el-table> -->

            <el-table
              ref="table2"
              :data="peopleList"
              :height="tableHeight"
              :row-class-name="tableRowClass"
              row-key="menuId"
              stripe
              border
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
              @sort-change="(column)=>{sortChange(column, this)}"
              @row-click="singleElection2"
            >
              <Column v-for="(column,index) in peopleColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
            </el-table>
            <!-- </div> -->
          </div>
          <div class="item_list">
            <pagination
              :total="total"
              :page.sync="pageData.pageNum"
              :limit.sync="pageData.pageSize"
              :selected-num="selectionsAll&&selectionsAll.length"
              @pagination="loadPeople"
            />
          </div>
        </div>

      </div>
    </div>
    <!-- <div style="margin-top:20px" class="main_bottom">
      <el-button type="cancel" @click.stop="cancel">取消</el-button>
      <el-button @click.stop="onSubmit">保存</el-button>
    </div> -->
  </div>
</template>

<script>
import {
  list,
  remove,
  updateUser,
  changeStatus,
  importMethod
} from '@/api/system/user'
import {
  treeselect as getDeptTree,
  delDept as removeDept,
  selectUserByDeptId
} from '@/api/system/dept'
// import { list, remove } from '@/api/equipmentManage/baseInfo/maintenanceTeam'
// import { personnellist } from '@/api/equipmentManage/equipmentRepair/equipmentReportRepair'
import AddOrUpdate from '../../saleManage/customerInfo/addUser.vue' // 新增或编辑页面

export default {
  name: 'Index',
  props: {
    layerid: {},
    teamId: {},
    peopleId: {},
    userId: {},
    defaultValue: {}
  },
  data() {
    return {
      // loading: true,
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        status: 1,
        searchValue: ''
      },
      teamListArr: [],
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      serviceId: '',
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      peopleList: [],
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      teamColumns: [// 表格常规字段（初始值）
        { prop: 'name', label: '维保班组名称' }
      ],
      peopleColumns: [// 表格常规字段（初始值）
        { prop: 'realName', label: '姓名' },
        { prop: 'phonenumber', label: '手机号' },
        { prop: 'email', label: '邮箱' },
        { prop: 'deptName', label: '部门' }
      ],
      defaultSearchColumns: [// 搜索区常规字段（初始值）
        { prop: 'code', label: '维保班组编码', type: 'input' },
        { prop: 'name', label: '维保班组名称', type: 'input' },
        { prop: 'crewNames', label: '维保人员', type: 'input' },
        { prop: 'status', label: '状态', type: 'select', optionsName: 'statusOptions' }
      ],

      operationData: [ // 右上角的操作按钮
        { label: '新增', perm: '' },
        { label: '批量操作', perm: '' },
        { label: '批量删除', perm: '' },
        { label: '页面配置', perm: '' }
      ],

      statusOptions: [ // 选择组件数据源
        { value: undefined, label: '全部' },
        { value: '1', label: '启用' },
        { value: '0', label: '停用' }
      ],
      templateSelection: undefined,
      selectionsRow: {},
      templateSelection2: undefined,
      selectionsRow2: {},
      baseMaintenanceId: undefined,
      defaultProps: {
        label: 'label',
        children: 'children'
      }
    }
  },
  mounted() {
    // this.defaultSearchColumns[1].options = this.statusOptions // 给 defaultSearchColumns 赋值
    this.getLists()

    this.templateSelection = this.teamId
    this.templateSelection2 = this.peopleId
    this.serviceId = this.userId
    this.loadPeople()
  },
  methods: {
    refreshs() {
      console.log('调用了')
      this.loadPeople()
    },
    getLists() {
      getDeptTree(this.pageData).then(res => {
        // this.tableData = res.data
        this.teamListArr = res.data
        this.loading = false
        this.$nextTick(() => {
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    getList() {
      getDeptTree(this.pageData).then(res => {
        this.teamListArr = res.data
        this.loading = false
        this.$nextTick(() => {
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    // 加载点检人员数据
    // loadPeople() {
    //   list({
    //     searchValue: this.pageData.searchValue,
    //     ...this.pageData
    //   }).then(res => {
    //     this.total = res.total
    //     this.peopleList = res.data
    //     this.peopleList.forEach(ele => {
    //       ele.deptName = ele.dept.deptName
    //     })
    //   })
    // },
    loadPeople() {
      const cachePageData = this.$deepClone(this.pageData)
      cachePageData.deptId = this.templateSelection
      selectUserByDeptId(cachePageData).then((res) => {
        this.peopleList = res.data
        this.total = res.total
        this.$nextTick(() => {
          this.setSelectRow(this) // 设置行选中
        })
      })
    },
    tableRowClass({ row }) {
      if (row.userId == this.serviceId) {
        return 'rowSelected'
      }
      return ''
    },
    // 根据点检人员id查询维保班组
    searchTeam(e) {
      this.peopleList.forEach(item => {
        if (item.userId == e.userId) {
          this.templateSelection = item.maintenanceId
        }
      })
    },
    // 单选
    singleElection(row) {
      this.selectionsRow = row
      this.templateSelection = row.id
      this.loadPeople()
    },
    // 单选
    singleElection2(row) {
      // this.selectionsRow2 = row
      // this.templateSelection2 = row.userId
      // this.searchTeam(row)
      // this.$parent.showTeamAndPeople(this.templateSelection, this.templateSelection2, this.selectionsRow2)
      this.$parent.showPeople(row)
      this.$layer.close(this.layerid)// 关闭弹框
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            defaultValue: {
              parentId: 0,
              parentName: '根目录'
            }
          }// props
        },
        area: ['440px', '705px'],
        title: '新增用户', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    cancel() {
      this.$layer.close(this.layerid)// 关闭弹框
    },
    // onSubmit() {
    //   this.$parent.showTeamAndPeople(this.templateSelection, this.templateSelection2, this.selectionsRow2)
    //   this.$layer.close(this.layerid)// 关闭弹框
    // },
    // 当前页的删除接口
    deleteMethod(deleteIds) {
      return remove(deleteIds)
    }

  }
}
</script>

<style lang="less" scoped>
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
.twoTable{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding:0px 30px;
}
.table_container{
  margin-top:20px !important;
}
main_main_search_item{
  .el-input{
    width:230px !important;
    margin-right:10px !important;
  }
  .el-button{
    background:#387bfc !important;
    width:30px !important;
  }
}
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  margin-left: 10px !important;
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}
.main_main {
  height: calc(100% - 50px);
}
.main_main_container {
  width: 100%;
  height: 100%;
  display: flex;

  .main_main_left {
    width: 250px;
    height: calc(100% - 20px);
    padding-right: 20px;
    .title {
      padding: 10px 0;
      border-bottom: 1px solid #387BFC;
      margin-bottom: 10px;
    }
    .main_main_left_top {
      width: 100%;
      height: calc(100% - 80px);
      overflow-y: auto;
      .el-tree {
        background-color: transparent;
      }
      /deep/ .el-tree-node__content:hover {
        background-color: rgba(56, 123, 252, 0.5) !important;
        color: white;
      }
    }
    .main_main_left_bottom {
      width: 100%;
      .main_main_left_bottom_item {
        background-color: rgba(74, 77, 82, 0.2);
        height: 40px;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-left: 24px;
      }
      .main_main_left_bottom_item:last-child {
        border-top: 1px solid white;
      }
      .main_main_left_bottom_item:hover {
        background-color: rgba(56, 123, 252, 0.5);
        color: white;
      }
      .active {
        .main_main_left_bottom_item {
          background-color: rgba(56, 123, 252, 1);
          color: white;
        }
      }
    }
  }
  .main_main_right {
    width: calc(100% - 250px);
    height: 100%;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #ECECEC;

  }
}
.button{
    width: 100px;
    height: 30px;
    color: #fff;
    background-color: #387bfc;
    border-radius: 4px;
    text-align: center;
    line-height: 30px;
}
.formItem_header{
  justify-content: flex-start !important;
  align-items: flex-start !important;
  height: 40px !important;
  padding-left: 10px !important;
}
.item_list{
  margin: 20px;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search{
  padding-right: 20px !important;
}
.main_main_search_item{
  padding-left: 10px !important;
}
.main_main{
  margin-right:0 !important;
  padding-top:0 !important;
}
.button_icon{
 background:#387bfc;
 width:30px;
}
.search_input{
  width:200px;
  margin-right:10px
}
/deep/.el-button--default {
  width: 30px !important;
}
/deep/ .el-input--suffix {
  margin-right: 10px !important;
}
</style>
